<script setup>
import { onMounted, ref } from "vue";
import { initThree, render, updateLabel } from "../assets/js/threeObj";

import { ElMessage } from "element-plus";

import { listModel, run, stop } from "../http/api.js";

const modelArr = ref([]);
const runModel = ref(null);
const visible = ref(false);

getModel();

function getModel() {
  listModel().then((res) => {
    modelArr.value = res;
  });
}
function closeSet() {
  visible.value = false;
}
function actionFn(type) {
  if (type == 1) {
    if (!runModel.value) {
      ElMessage({
        message: "请选择运行模式",
        type: "warning",
      });
      return;
    }
    run({
      script_name: runModel.value,
    }).then((res) => {
      ElMessage({
        message: res.message,
        type: "success",
      });
      visible.value = false;
    });
  } else {
    stop({
      script_name: runModel.value,
    }).then((res) => {
      ElMessage({
        message: res.message,
        type: "success",
      });
      visible.value = false;
    });
  }
}

function showSetFn() {
  visible.value = true;
}

onMounted(() => {
  initThree("td");
  render();
  setTimeout(() => {
    updateLabel();
  }, 1000);
});
</script>

<template>
  <div class="set" @click="showSetFn()">设置</div>
  <div id="td"></div>
  <div class="set-box" v-show="visible">
    <div class="in-set-box">
      <div class="set-title">
        设置
        <div class="close" @click="closeSet()"></div>
      </div>
      <div class="set-con">
        <p>运行模式</p>
        <el-select placeholder="请选择运行模式" v-model="runModel" clearable>
          <el-option
            v-for="item in modelArr"
            :value="item"
            :label="item"
          ></el-option>
        </el-select>
        <div class="set-btn">
          <div class="even-btn run" @click="actionFn(1)">开始运行</div>
          <div class="even-btn stop" @click="actionFn(0)">停止运行</div>
        </div>
      </div>
    </div>
  </div>
</template>
<style lang="scss" scoped>
.set {
  position: absolute;
  width: 84px;
  height: 30px;
  right: 20px;
  top: 20px;
  background: url("../assets/img/set.png") center center no-repeat;
  background-size: 84px auto;
  z-index: 9;
  cursor: pointer;
  line-height: 28px;
  text-indent: 40px;
  color: #c4d8f1;
}
.set-box {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9;
  .in-set-box {
    width: 453px;
    height: 304px;
    background: url("../assets/img/set_bg.png") center center no-repeat;
    z-index: 10;
    .set-title {
      color: #c4d8f1;
      line-height: 34px;
      text-indent: 20px;
      letter-spacing: 6px;
      position: relative;
      .close {
        position: absolute;
        width: 34px;
        height: 34px;
        right: 0;
        top: 4px;
        cursor: pointer;
        background: url("../assets/img/set_close.png") center center no-repeat;
        background-size: 16px auto;
      }
    }
    .set-con {
      padding: 50px 100px;
      height: 270px;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      p {
        text-align: center;
        font-size: 16px;
        color: #c4d8f1;
      }
    }
    .set-btn {
      display: flex;
      justify-content: space-between;
      .even-btn {
        width: 110px;
        height: 42px;
        margin-top: 20px;
        text-align: center;
        color: #c4d8f1;
        line-height: 42px;
        cursor: pointer;
        &.run {
          background: url("../assets/img/run.png") left bottom no-repeat;
          background-size: 110px 42px;
        }
        &.stop {
          background: url("../assets/img/stop.png") left bottom no-repeat;
          background-size: 110px 42px;
        }
      }
    }
  }
}
</style>
<style lang="scss">
#td {
  width: 100%;
  height: 100%;
  background: url("../assets/img/tdbg.png") center center no-repeat;
}
.labelTitles {
  width: 279px;
  height: 142px;
  background: url("../assets/img/default.png") center center no-repeat;
  background-size: cover;
  color: #ffffff;

  .title {
    width: 100%;
    height: 38px;
    padding: 0 0 3px 22px;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    font-size: 18px;
    text-shadow: 0 0 5px #0e71ff, /* 白色主阴影 */ 0 0 10px #0e71ff;
    /* 蓝色次阴影 */
    .closeIcon {
      width: 22px;
      height: 22px;
      background: url(../assets/img/close.png) center center no-repeat;
      background-size: 12px auto;
      cursor: pointer;
    }
  }
  .center {
    width: 100%;
    height: calc(100% - 38px);
    display: flex;
    flex-direction: column;
    padding: 0 0 10px 22px;
    justify-content: space-evenly;
  }
}
.labelTitles.default {
  .labelNrwd {
    color: #ffffff;
  }
}
.labelTitles.cyan {
  background: url("../assets/img/cyan.png") center center no-repeat;
  background-size: cover;
  .title {
    text-shadow: 0 0 5px #bbffee, /* 白色主阴影 */ 0 0 10px #bbffee;
  }
}
.labelTitles.red {
  background: url("../assets/img/red.png") center center no-repeat;
  background-size: cover;
  .title {
    text-shadow: 0 0 5px #ff1010, /* 白色主阴影 */ 0 0 10px #ff1010;
  }
}
.labelTitles.orange {
  background: url("../assets/img/orange.png") center center no-repeat;
  background-size: cover;
  .title {
    text-shadow: 0 0 5px #ff690e, /* 白色主阴影 */ 0 0 10px #ff690e;
  }
}
.labelTitles.purple {
  background: url("../assets/img/purple.png") center center no-repeat;
  background-size: cover;
  .title {
    text-shadow: 0 0 5px #8650ff, /* 白色主阴影 */ 0 0 10px #8650ff;
  }
}
.labelTitles.yellow {
  background: url("../assets/img/yellow.png") center center no-repeat;
  background-size: cover;
  .title {
    text-shadow: 0 0 5px #fad60d, /* 白色主阴影 */ 0 0 10px #fad60d;
  }
}
.labelNrwd.default {
  color: #ffffff;
}
.labelNrwd.red {
  color: #ff1010;
}
.labelNrwd.orange {
  color: #ff690e;
}
.labelNrZtWd.default,
.labelNrwd.default {
  color: #2ae982;
}
.labelNrZtWd.red,
.labelNrwd.red {
  color: #ff1010;
}
.labelNrZtWd.orange,
.labelNrwd.orange {
  color: #ff690e;
}

.labelNrZtYb.default,
.labelyb.default {
  color: #2ae982;
}
.labelNrZtYb.purple,
.labelyb.purple {
  color: #8650ff;
}
.labelNrZtYb.yellow,
.labelyb.yellow {
  color: #fad60d;
}
</style>
